df <- t_sub@reductions[["umap"]]@cell.embeddings %>%
    as.data.frame() %>%
    rownames_to_column("cell") %>%
    as_tibble() %>%
    inner_join(t_sub@meta.data %>% as.data.frame() %>%
        rownames_to_column("cell") %>% select(any_of(c("cell", "CellStatus"))))

corner_point_coordinate <- list(x = min(df[[2]]),y = min(df[[3]]))  %>% map(~ .x -.3)

line_data <- tibble(
    x1 = c(rep(corner_point_coordinate$x, 3), corner_point_coordinate$x + 3),
    y1 = c(corner_point_coordinate$y, corner_point_coordinate$y + 3, rep(corner_point_coordinate$y, 2)),
    group = c(1, 1, 2, 2)
)

label_data <- tibble(
    x1 = c(corner_point_coordinate$x - .7, corner_point_coordinate$x + 1.5),
    y1 = c(corner_point_coordinate$y + 1.5, corner_point_coordinate$y - .7),
    label = colnames(df)[c(3,2)], angle = c(90, 0)
)

p <- ggplot2::ggplot(
    df,
    ggplot2::aes_string(x = colnames(df)[2], y = colnames(df)[3])
) +
    ggplot2::geom_point(ggplot2::aes_string(color = "CellStatus"),
        size = .4,
        show.legend = T
    ) +
    ggplot2::labs(x = "", y = "") +
    cowplot::theme_map() +
    ggplot2::geom_line(
        data = line_data,
        ggplot2::aes(x = x1, y = y1,group = group),
        color = "black",
        arrow = ggplot2::arrow(
            length = ggplot2::unit(0.1, "inches"),
            ends = "last",
            type = "closed"
        )
    )+
    ggplot2::geom_text(
        data = label_data,
        ggplot2::aes(x = x1, y = y1, angle = angle, label = label),
        color = "black",
        fontface = "italic",
        size = 3
    ) +
    ggplot2::guides(color = ggplot2::guide_legend(override.aes = list(size = 2)))
    

legend_  <-  ggpubr::get_legend(p)
p <- p+theme(legend.position = 'none')

p2 <- ggpubr::ggarrange(p,legend_,ncol = 2,nrow = 1,widths = c(1,.75))

plotout(p = p2,name = 'a',od = 'out/SC_part/03.tsub',w = 6,h = 3.6)



# object,
#   dims = c(1, 2),
#   cells = NULL,
#   cols = NULL,
#   pt.size = NULL,
#   reduction = NULL,
#   group.by = NULL,
#   split.by = NULL,
#   shape.by = NULL,
#   order = NULL,
#   shuffle = FALSE,
#   seed = 1,
#   label = FALSE,
#   label.size = 4,
#   label.color = "black",
#   label.box = FALSE,
#   repel = FALSE,
#   cells.highlight = NULL,
#   cols.highlight = "#DE2D26",
#   sizes.highlight = 1,
#   na.value = "grey50",
#   ncol = NULL,
#   combine = TRUE,
#   raster = NULL,
#   raster.dpi = c(512, 512)